#include "Light.h"

bool LightObject::Init(IDirect3DDevice9* Device,eAllLights Light)
{
	Device->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
	Device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(60, 60, 60));

	ZeroMemory(&m_Light, sizeof(D3DLIGHT9));

	m_Light.Type = D3DLIGHT_POINT;
	m_Light.Ambient = D3DXCOLOR(0.1f, 0.1f, 0.1f, 0.1f);
	m_Light.Diffuse = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1);	// color of the light
	m_Light.Specular = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1);
	m_Light.Position.x = 0;	
	m_Light.Position.y = 0;	
	m_Light.Position.z = -30;
	D3DXVec3Normalize((D3DXVECTOR3*)&m_Light.Direction, (D3DXVECTOR3*)&m_Light.Position);
	m_Light.Range = 70.0f;
	m_Light.Attenuation0 = 0;
	m_Light.Attenuation1 = 0.01f;
	m_Light.Attenuation2 = 0.0f;

	Device->SetLight(Light, &m_Light);
	Device->LightEnable(Light, true);

	m_Index = Light;

	if(&m_Light == new D3DLIGHT9())
		return false;
	return true;
}

bool LightObject::SetLight(IDirect3DDevice9* Device,eAllLights Light)
{
	HR(Device->SetLight(Light,&m_Light));
	HR(Device->LightEnable(Light, State));
	return true;
}

bool LightObject::MoveLight(D3DXVECTOR3 P)
{
	m_Light.Position.x = P.x;
	if(m_Light.Position.x != P.x)
		return false;
	
	m_Light.Position.y = P.y;
	if(m_Light.Position.y != P.y)
		return false;
	
	m_Light.Position.z = P.z;
	if(m_Light.Position.z != P.z)
		return false;

	return true;
}

bool LightObject::MoveLight(float x,float y,float z)
{
	
	m_Light.Position.x = x;
	if(m_Light.Position.x != x)
		return false;
	
	m_Light.Position.y = y;
	if(m_Light.Position.y != y)
		return false;
	
	m_Light.Position.z = z;
	if(m_Light.Position.z != z)
		return false;
	return true;
}

bool LightObject::LightSwitch(bool Flip)
{
	State = Flip;
	if(State != Flip)
		return false;
	return true;
}

bool LightObject::TurnUp(float Intensity)
{
	m_Light.Range = Intensity;
	return true;
}